package com.atguigu.gmall.product.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.model.product.BaseTrademark;
import com.atguigu.gmall.product.service.BaseTrademarkService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 *
 */
@RestController
@RequestMapping("/admin/product")
public class BaseTradeMarkController {

    @Autowired
    private BaseTrademarkService baseTrademarkService;


    /**
     品牌分页列表
     * /admin/product/baseTrademark/{page}/{limit}

    */
    @ApiOperation("品牌分页列表")
    @GetMapping("/baseTrademark/{page}/{limit}")
    public Result baseTrademark(@PathVariable Long page,
                                @PathVariable Long limit){

        //封装分页对象
        Page<BaseTrademark> baseTrademarkPage = new Page<>(page, limit);

        IPage<BaseTrademark> baseTrademarkIPage = baseTrademarkService.baseTrademark(baseTrademarkPage);
        return Result.ok(baseTrademarkIPage);
    }

    /**
     /admin/product/baseTrademark/get/{id}
     * 回显：根据id查询品牌对象

    */
    @GetMapping("/baseTrademark/get/{id}")
    public Result getTradeMarkById(@PathVariable Long id ){

        BaseTrademark baseTrademark = baseTrademarkService.getById(id);
        return Result.ok(baseTrademark);
    }

    /**
     * admin/product/baseTrademark/update
     * 修改品牌
     * @param baseTrademark
     * @return
     */
    @PutMapping("/baseTrademark/update")
    public Result updateTradeMark(@RequestBody BaseTrademark baseTrademark){

        baseTrademarkService.updateById(baseTrademark);
        return Result.ok();

    }


    /**
     * /admin/product/baseTrademark/save
     * 保存品牌
     * @param baseTrademark
     * @return
     */
    @PostMapping("/baseTrademark/save")
    public Result saveBaseTradeMark(@RequestBody BaseTrademark baseTrademark){


        baseTrademarkService.save(baseTrademark);

        return Result.ok();

    }


    /**
     * admin/product/baseTrademark/remove/{id}
     * 根据id删除品牌对象
     * @param id
     * @return
     */
    @DeleteMapping("/baseTrademark/remove/{id}")
    public Result removeTradeMark(@PathVariable Long id){
        baseTrademarkService.removeById(id);
        return Result.ok();
    }


}
